<?php

namespace App\Handler\Admin\Structure\Enterprise;

use App\Handler\Admin\AbstractCommon;
use App\Service\Archives;
use App\Service\Templates;
use App\Service\UPFile;
use App\Tools\Html;
use Phoenix\Support\MsgHelper;
use Exception;

/**
 * 文档修改
 */
class Edit extends AbstractCommon {

    protected function __Inject($db, $cache, $session, UPFile $upFile,
                                Archives $serviceArchives = null, Templates $toolsTemplates = null) {}

    public function processRequest(Array & $context) {
        try {
            $this->db->beginTransaction();

            $this->_pushSetting();

            $_POST['title'] = Html::getTextToHtml($_POST['title']);
            $_POST['synopsis'] = Html::getTextToHtml($_POST['synopsis']);
            $_POST['type_id'] = 5;
            $_POST['sort'] = isset($_POST['sort']) ? intval($_POST['sort']) : 0;
            $_POST['release_date'] = time();
            $_POST['certificate_id'] = $_POST['id'];

            $this->db->debug();
            $_return = $this->db->table('`#@__@certificate`')
                ->row(array(
                    '`type_id`' => '?',
                    '`title`' => '?',
                    '`synopsis`' => '?',
                    '`cover`' => '?',
                    '`sort`' => '?',
                    '`release_date`' => '?',
                ))
                ->where('`certificate_id` = ?')
                ->bind($_POST)
                ->update();

            $this->db->commit();

            echo(MsgHelper::json($_return ? 'SUCCESS' : ($_return == 0 ? 'NO_CHANGES' : 'DB_ERROR')));
        } catch (Exception $e) {

            $this->db->rollBack();
            echo(MsgHelper::json('DB_ERROR'));
        }
    }

}
